import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


public class IndexRepository implements Serializable {
	
	private static final long serialVersionUID = 1L;

	public IndexRepository() {
		repository = new ArrayList<Index>();
	}
	
	private List<Index> repository;

	public Index search(String url) {
		
		return getIndexFromRepo(url);
		
	}

	private Index getIndexFromRepo(String url) {
		
		for (Index index : repository) {
			if (index.getUrl().equals(url)) 
			{
				return index;
			}
		}
		return null;
	}

	public void update(String url, int hashCodeAtual) {
		repository.remove(getIndexFromRepo(url));
		
		insert(url,hashCodeAtual);
		
	}

	public void insert(String url, int hashCodeAtual) {
		repository.add(new Index(url,hashCodeAtual));
	}

}
